#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <map>
#include <functional>
#include <string>
#include <vector>
#include <stack>
using namespace std;
class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<int>st;
        map<string, function<int(int, int)>>opFuncMap = {
          {"+",[](int x,int y) {return x + y; }},
          {"-",[](int x,int y) {return x - y; }},
          {"*",[](int x,int y) {return x * y; }},
          {"/",[](int x,int y) {return x / y; }}
        };
        for (auto str : tokens)
        {
            if (opFuncMap.count(str))
            {
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();
                int ret = opFuncMap[str](left, right);
                st.push(ret);
            }
            else
            {
                st.push(stoi(str));
            }
        }
        return st.top();
    }

};
